x = 3
weight = 2
target = 10

learning_rate = 0.01

for i in range(100000):
    # 损失方向
    sign = 1 if x * weight - target > 0 else -1
    # 损失值
    loss_value = (weight * x - target) ** 2
    # 损失/权重的斜率
    loss_value_weight_slope = loss_value / weight * sign
    log = f'损失值：{loss_value:.5f}，权重：{weight:.5f}，预测值：{x * weight:.5f}，损失/权重斜率：{loss_value_weight_slope:.5f}'
    print(log)
    # 新的权重
    weight = weight - learning_rate * loss_value_weight_slope
